import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:mtf/app/base/BaseController.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/widget/VercodeTimerWidget.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class resetPasswordController extends BaseController{
  TextEditingController phoneController = TextEditingController();
  TextEditingController passwordController = TextEditingController();
  TextEditingController password2Controller = TextEditingController();
  TextEditingController yzmController = TextEditingController();
  VercodeController verController = VercodeController();
  var _isOneObscure=false.obs;

  set OneObscure(value) => _isOneObscure.value = value;
  get OneObscure => _isOneObscure.value;
  var _isTwoObscure=false.obs;
  set TwoObscure(value) => _isTwoObscure.value = value;
  get TwoObscure => _isTwoObscure.value;
  var _isCheckObs=false.obs;
  set CheckObs(value) => _isCheckObs.value = value;
  get CheckObs => _isCheckObs.value;

  void reqYzm() async{
    var phone=phoneController.text;
    if(phone.isEmpty){
      SmartDialog.showToast("请输入手机号");
    }else{
      var resp=await HttpManager.reqYzm(phone, "password_reset");
      if(resp.isSuccess()){
        verController.vercodeSend();
      }
    }
  }

  void clickResetPassword()async{
    var phone=phoneController.text;
    var yzm=yzmController.text;
    var psw1=passwordController.text;
    var psw2=password2Controller.text;
    if(phone.isEmpty){
      SmartDialog.showToast("请输入手机号");
    }else if(yzm.isEmpty){
      SmartDialog.showToast("请输入短信验证码");
    }else if(psw1.isEmpty||psw2.isEmpty){
      SmartDialog.showToast("请输入新密码");
    }else if(psw1!=psw2){
      SmartDialog.showToast("请确保两次密码一致");
    }else{
      showLoading();
      var resp= await HttpManager.reqForgetPsw(phone,yzm,psw1,psw2);
      if(resp.isSuccess()){
        SmartDialog.showNotify(msg: "重置密码成功", notifyType: NotifyType.success);
        Get.back();
      }
      hideLoading();
    }
  }
}
